﻿/* 
	When pressed will take the current Subtool and apply a detail enhancement. (Uses the process of duplicating morph target details through layers.)
*/

/////////////////////////////////////////
// User Changeable Options ///////////////
/////////////////////////////////////////

[VarDef,gPolishTimes,1] // Sets how many Polish Deformation passes will be done before generating the layers (Default 1)

/////////////////////////////////////////
/////////////////////////////////////////

// Example rename layer usage: [RoutineCall,RenameIt,"New Subtool Name",1]
[RoutineDef,RenameIt,

	// Set DLL location
	[If,[ZBrushInfo,6],
		[VarSet,gFileUtils,[FileNameResolvePath,"ZSTARTUP_ZPLUGS64/MacroData/ZFileUtils.lib"]]
	, //Windows
		[VarSet,gFileUtils,[FileNameResolvePath,"ZSTARTUP_ZPLUGS64/MacroData/ZFileUtils64.dll"]]
	]

	[If,option,
		// Rename Subtool
		[VarSet,buttonPath,"Tool:SubTool:Rename"]
	,
		// Rename Layer
		[VarSet,buttonPath,"Tool:Layers:Rename"]
	]

	// Process Renaming
  	[If, (([IExists,buttonPath]) && ([IsEnabled,buttonPath])),
  		[FileExecute,[Var,gFileUtils],RenameSetNext,text]
		[IPress,buttonPath]
	]

,text,option]

// Example DisplayNoteTwo usage: [RoutineCall,DisplayNoteTwo,"Save file?"]
[RoutineDef,DisplayNoteTwo,

	/*1*/[NoteIButton,"OK",,,,,,,,,0xffffff,,,]
	/*2*/[NoteIButton,"CANCEL",,,,,,,,,0xffffff,,,]
	[VarSet,result,[Note,note,,,0x1f1f1f,,,,,,,,IMAGE_ZLogoForNotes.psd]]
	[Loop,1000,
		[If,result==1,
			//OK
		,]
		[If,result==2,
			//CANCEL
			[Exit]
		,]
	]

,note]


[RoutineDef,EnhanceDetails,
	
	// Display Warning if the Subtool has layers
	[If,[IsEnabled,"Tool:Layers:Layers Scrollbar"],
		[VarSet,tempnote,"The current Subtool contains layers. This process will bake the layers before enhancing. Proceed? \n\nPress 'OK' to continue or 'CANCEL' to abort."]
		[RoutineCall,DisplayNoteTwo,tempnote]
	,]

	// Prep the Subtool
	[IPress,Tool:Masking:Clear]
	[IPress,Tool:Layers:Bake All]
	[IPress,Tool:Morph Target:StoreMT]
	
	// Smooth out the details using Polish
	[VarSet,PolishModSetting,[IModGet,"Tool:Deformation:Polish"]]
	[IModSet,Tool:Deformation:Polish,1]
	[Loop,gPolishTimes,
		[ISet,Tool:Deformation:Polish,100]
	]

	// Create Layers
	[IPress,Tool:Layers:New]
	[IPress,Tool:Morph Target:Switch]
	[IPress,Tool:Layers:New]
	[IPress,Tool:Layers:Delete]
	[RoutineCall,RenameIt,"Enhanced",0]
	[IPress,Tool:Layers:Duplicate]
	[RoutineCall,RenameIt,"Original",0]

	// Return Polish setting
	[IModSet,Tool:Deformation:Polish,PolishModSetting]

]

[IButton,???,"When pressed will take the current Subtool and apply a detail enhancement using layers (Edit Macro for Options.)",
	[IShowActions,0]
	[IConfig,4.8]
	//[IFreeze,
		[RoutineCall,EnhanceDetails]
	//]
,,1,,,]